package com.hd.assistant.dal.dao.ibatis.ordermining;

import java.util.List;

import com.hd.assistant.dal.dao.exception.DAOException;
import com.hd.assistant.dal.dao.orderming.ITaskDAO;
import com.hd.assistant.dal.dataobject.ordermining.ITask;
import com.taobao.common.dao.persistence.DBRoute;
import com.taobao.common.dao.persistence.SqlMapBaseDAO;

public class IbatisITaskDao extends SqlMapBaseDAO implements ITaskDAO {

	@Override
	public void insertTask(ITask task) throws DAOException {
		if (task == null)
			throw new DAOException("ERROR PARAMS: task == nul");
		try {
			this.executeInsert("Task.insertTaskDO", task,
					DBRoute.getOrderMiningRoute());
		} catch (com.taobao.common.dao.persistence.exception.DAOException e) {
			throw new DAOException("insertTask", e);
		}
	}

	@Override
	public int updateTask(ITask task) throws DAOException {
		if (task == null || task.getTaskId() == null)
			throw new DAOException("ERROR PARAMS: task == nul");
		try {
			return this.executeUpdate("Task.updateTask", task,
					DBRoute.getOrderMiningRoute());
		} catch (com.taobao.common.dao.persistence.exception.DAOException e) {
			throw new DAOException("updateTask", e);
		}
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ITask> getTaskByUserIdAndType(Long userId, String type)
			throws DAOException {
		if (userId == null || type == null)
			throw new DAOException("ERROR PARAMS: userId == null || type == null");
		ITask task = new ITask();
		task.setUserId(userId);
		task.setType(type);
		try {
			return (List<ITask>)this.executeQueryForList("Task.getTaskByUserIdAndType", task,
					DBRoute.getOrderMiningRoute());
		} catch (com.taobao.common.dao.persistence.exception.DAOException e) {
			throw new DAOException("getTaskByUserIdAndType", e);
		}
	}

	@Override
	public ITask getTaskByTaskId(Long taskId) throws DAOException {
		if (taskId == null )
			throw new DAOException("ERROR PARAMS: taskId == null ");
		try {
			return (ITask)this.executeQueryForObject("Task.getTaskByTaskId", taskId,
					DBRoute.getOrderMiningRoute());
		} catch (com.taobao.common.dao.persistence.exception.DAOException e) {
			throw new DAOException("getTaskByTaskId", e);
		}
	}

}
